<template>
	<view class="main">
		<tou_hand1 handtitle='场地险购买记录'></tou_hand1>
		<view class="show">
			<view class="sel">
				<image src="https://qiniu.jxyutuo.com/yanqin/tabBarimg//cdxselect.png"></image>
				<input placeholder='小区名称搜索' v-model="name" @input="onInput"/>
			</view>
			
			<view class="one">
				<view class="onetxt">
					总金额：<span style="font-weight: 700;">¥{{money}}</span>
				</view>
				<view class="cdjl-0" v-if="value">
					<view class="cdjl-0-l" @click="onShowDatePicker('range')">
						{{value[0]}}
					</view>-
					<view class="cdjl-0-l" @click="onShowDatePicker('range')">
						{{value[1]}}
					</view>
				</view>
			</view>
			<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
			<van-list v-model="loading" :offset="300" :finished="finished" finished-text="没有更多了" @load="loadMore">
			<van-cell v-for="(item, index) in blist" :key="index" >
				<view class="two">
					<view class="twofirst">
						<view class="twofirstleft">
							订单金额：<span>￥{{item.orderMoney}}</span>
						</view>
						<view class="twofirstright">
							{{item.createTime}}
						</view>
					</view>
					<view class="twosecond">
						<view class="twosecondleft">
							订单编号：<span>{{item.orderNo}}</span>
						</view>
					</view>
					<view class="twosecond">
						<view class="twosecondleft">
							端口单价：<span>{{item.portMoney}}</span>（元/年）
						</view>
					</view>
					<view class="twosecond">
						<view class="twosecondleft">
							设备数量：<span>{{item.deviceNum}}个</span> | 端口数量：<span>{{item.portsNum}}个</span>
						</view>
					</view>
					<view class="twosecond">
						<view class="twosecondleft">
							购买期限：<span>{{item.expireData}}年</span>
						</view>
						<view class="twosecondright" @click="detailbtn(item.orderNo)">
							订单详情
						</view>
					</view>
				</view>
				
				
			</van-cell>
			</van-list>
			</van-pull-refresh>	
		</view>
		<date-picker :show="showPicker" :type="type" class="mask" :value="value" :show-tips="true" :begin-text="'开始'"
		 :end-text="'结束'" :show-seconds="true" @confirm="onSelected" @cancel="onCancel"></date-picker>	
	</view>
</template>

<script>
	import tou_hand1 from '../../components/tou_hand1/tou_hand1.vue'
	import datePicker from "../../components/mx-datepicker.vue";
	import {formatDate} from '../../common/formatDate.js'
	export default {
		components: {tou_hand1,datePicker},
		mounted() {
			
		},

		data() {
			return {
				value: ['请选择开始时间', '请选择结束时间'],
				type: 'range', //时间选择器
				showPicker: false, //时间选择器
				blist:[],//本区消费数据
				loading: false,
				finished: false,
				refreshing: false,
				pageNum: 1, //页码
				pageSize: 10, //每页显示的条数
				money:0,
				name:''
			}
		},
		onLoad(option) {
			this.show();
			this.loadMore();
		},
		methods: {
			show(){
				var nowtime = formatDate(new Date(),'yyyy-MM-dd');				
				var oldtime=formatDate(new Date(new Date().getTime()-2592000000),'yyyy-MM-dd');
				this.value=[oldtime,nowtime]
			},
			// 用户统计详情分页
			loadMore() {
				if (this.refreshing) {
				  this.blist = [];
				  this.refreshing = false;
				}
				const that = this;
				let data = {
					pageNum:that.pageNum,
					pageSize:that.pageSize,
					startTime:that.value[0],
					endTime:that.value[1],
					projectName:that.name
				}
				that.loading = true;
				that.$base.request1('manager/site/order/list', 'POST', data)
					.then(res => {
						that.loading = false;
						if(res.data.code==0){
							that.money=res.data.msg
							if(res.data.rows&&res.data.rows.length>0){
								that.blist = that.blist.concat(res.data.rows);
								that.pageNum += 1;
							}else{
								that.finished = true;
							}
						}else{
							that.finished = true;
						}
						
					})
					.catch(err => {
				
					})
			},
			 onRefresh() {
			      // 清空列表数据
			      this.finished = false;
				  this.pageNum=1
			      // 重新加载数据
			      // 将 loading 设置为 true，表示处于加载状态
			      this.loading = true;
			      this.loadMore();
			    },
			//选择时间点击确定
			onSelected(e) { //选择
				this.showPicker = false;
				if (e) {
					this[this.type] = e.value;
					for(var i=0;i<e.value.length;i++){
						e.value[i]=formatDate(new Date(e.value[i]),'yyyy-MM-dd')
					}
					this.value = e.value;
					this.blist = [];
					this.onRefresh()
				}
			},
			//选择时间点击取消
			onCancel() {
				this.showPicker = false;
				var nowtime = formatDate(new Date(),'yyyy-MM-dd');
				var oldtime=formatDate(new Date(new Date().getTime()-2592000000),'yyyy-MM-dd');
				this.value=[oldtime,nowtime]
				this.blist = [];
				this.onRefresh()
				
			},
			//点击时间框选择时间
			onShowDatePicker(type) { //显示
				this.type = type;
				this.showPicker = true;
			},
			detailbtn(orderNo){
				uni.navigateTo({
					url:'/pages/site_insurance_detail/site_insurance_detail?orderNo='+orderNo
				})
			},
			onInput(e){
				this.blist=[]
				this.onRefresh()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		/deep/.van-list__finished-text{
			margin-top: 100upx;
			padding-bottom: 200upx;
		}
		/deep/.van-hairline--top-bottom::after{
			border-width: 0;
		}
		.show{
			width: 100%;
			padding: 0 26upx;
			box-sizing: border-box;
			/deep/.van-cell{
				box-shadow: 0px 14upx 16upx 1upx rgba(22,86,176,0.2);
				border-radius: 10upx;
				padding: 36upx 20upx;
				width: 99%;
				margin: 0 auto;
				margin-top: 28upx;
			}
			// /deep/.van-cell__value{
			// 	box-shadow: 0px 14px 16px 1px rgba(22,86,176,0.2);
			// }
			/deep/.van-cell:not(:last-child)::after{
				border-bottom: 0upx;
			}
			.sel {
				// width: 90%;
				box-sizing: border-box;
				text-align: center;
				display: flex;
				border-radius: 44upx;
				padding: 15upx 20upx;
				background-color: #F5F5F5;
				align-items: center;
				// margin: 0 auto;
				margin-top: 20upx;
			
				image {
					width: 34upx;
					height: 34upx;
				}
			
				input {
					width: 100%;
				}
			
				/deep/.uni-input-placeholder {
					font-size: 30upx;
					font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
					font-weight: normal;
					color: #CECECE;
					line-height: 36upx;
				}
			}
			
			
			.one{
				width: 100%;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.onetxt{
					font-size: 32upx;
					font-family: PingFang-SC-Bold-, PingFang-SC-Bold;
					font-weight: normal;
					color: #666666;
					line-height: 38upx;
				}
				.cdjl-0 {
					display: flex;
					height: 100upx;
					background: #fff;
					align-items: center;
					justify-content: space-around;
					.cdjl-0-l {
						height: 60upx;
						width: 200upx;
						border-radius: 10upx;
						border: 2upx solid #ccc;
						font-size: 30upx;
						line-height: 60upx;
						color: #bbbbbb;
						text-align: center;
					}
				
					.cdjl-0-r {
						width: 120upx;
						height: 60upx;
						font-size: 20upx;
						background: #4e9ff6;
						color: #fff;
						line-height: 60upx;
						text-align: center;
						border-radius: 10upx;
					}
				}
			}
			.two{
				width: 100%;
				box-sizing: border-box;
				
				.twofirst{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 15upx;
					.twofirstleft{
						font-size: 32upx;
						font-family: PingFang SC-Heavy, PingFang SC;
						font-weight: 800;
						color: #666666;
						line-height: 38upx;
						span{
							color: #4B98ED;
						}
					}
					.twofirstright{
						font-size: 24upx;
						font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
						font-weight: normal;
						color: #999999;
						line-height: 29upx;
					}
				}
				.twosecond{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 15upx;
					.twosecondleft{
						font-size: 26upx;
						font-family: PingFang-SC-Regular-, PingFang-SC-Regular;
						font-weight: normal;
						color: #999999;
						line-height: 31upx;
						span{
							color: #666666;
						}
					}
					.twosecondright{
						text-align: center;
						font-size: 17upx;
						font-family: Yu Gothic UI-Regular, Yu Gothic UI;
						font-weight: 400;
						color: #0083FF;
						line-height: 22upx;
						padding: 12upx 36upx;
						border: 2upx solid #0083FF;
						border-radius: 10upx;
					}
				}
			}
		}
	}
</style>
